package com.gougou.manager.web.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.gougou.manager.pojo.TbItemCat;
import com.gougou.manager.service.MPTbItemCatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 商品类目 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2018-09-07
 */
@RestController
@RequestMapping("/tbItemCat")
public class TbItemCatController {
    @Autowired
    private MPTbItemCatService itemCatService;

    /********************************
     *
     *查询所有商品类型
     *
     * @return
     * ******************************
     */
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public List<TbItemCat> getItemCatList(@RequestParam(value = "id",defaultValue ="0" )long id){
        EntityWrapper<TbItemCat> wrapper = new EntityWrapper<TbItemCat>();
        wrapper.where("parent_id={0}",id);
        try {
            return itemCatService.selectList(wrapper);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;

    }

    /*******************************
     *
     * 通过id查询商品类型信息
     *
     * @param id
     * @return
     * ****************************
     */
    @RequestMapping(value = "/selectItemCatInfo/{id}",method = RequestMethod.GET)
    public TbItemCat selectItemCatByid(@PathVariable long id){
        try {
            return itemCatService.selectById(id);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    //查询商品类目的名称
    public String QueryTbItemCatGetName(Integer id){
        EntityWrapper<TbItemCat> tEntity = new EntityWrapper<TbItemCat>();
        tEntity.where("id={0}",id);
        System.out.println(tEntity);
        List<TbItemCat> tbItemCats = itemCatService.selectList(tEntity);
        return  tbItemCats.get(0).getName();
    }



}

